﻿using JinfuyuanProject.Entity;
using JinfuyuanProject.Repository.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JinfuyuanProject.Repository
{
    public class RoleAndPageRepository : IRoleAndPageRepository
    {
        private readonly JinfuyuanDbContext _db;

        public RoleAndPageRepository(JinfuyuanDbContext db)
    {
        _db = db;
    }
    public IQueryable<RoleAndPage> GetList()
    {
        try
        {
            return _db.RoleAndPage;
        }
        catch (Exception ex)
        {
            return null;
        }
    }
    public bool Delete(RoleAndPage roleAndPage)
    {
        try
        {

            _db.Entry(roleAndPage).State = System.Data.Entity.EntityState.Deleted;
            return _db.SaveChanges() > 0;
        }
        catch (Exception ex)
        {
            //记录异常日志
            return false;
        }
    }
    public RoleAndPage GetModel(int Id)
    {
        try
        {
                RoleAndPage roleAndPage = _db.RoleAndPage.Find(Id);
            return roleAndPage;
        }
        catch (Exception ex)
        {
            return null;
        }

    }

    public int Insert(RoleAndPage roleAndPage)
    {
        try
        {
            _db.Entry(roleAndPage).State = System.Data.Entity.EntityState.Added;
            _db.SaveChanges();
            return roleAndPage.Id;
        }
        catch (Exception ex)
        {
            return 0;
        }

    }

    public bool Update(RoleAndPage roleAndPage)
    {
        try
        {

            _db.Entry(roleAndPage).State = System.Data.Entity.EntityState.Modified;
            return _db.SaveChanges() > 0;
        }
        catch (Exception ex)
        {
            return false;
        }
    }
}
}

